/**
 * @author Pawel Gadecki <pidzama@gmail.com>
 * 
 */
package spwodne;

import java.util.List;
import javax.swing.table.AbstractTableModel;

public class MTNaleznosci extends AbstractTableModel {

    MTNaleznosci(Klient k) {
        klient = k;
        l = klient.getLNal();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        return l.size();
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        Object tmp;
        switch (col) {
            case 0: // '\0'

                tmp = ((Naleznosc) l.get(row)).kwota;
                break;

            case 1: // '\001'

                tmp = ((Naleznosc) l.get(row)).zostalo;
                break;

            case 2: // '\002'

                tmp = ((Naleznosc) l.get(row)).rok;
                break;

            default:
                System.out.println("getValue out of bounds");
                tmp = null;
                break;
        }
        return tmp;
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    public void addRow(float kwota, int rok) {
        klient.dodajNal(Float.valueOf(kwota), Integer.valueOf(rok));
        fireTableDataChanged();

    }

    public void delRow(int n) {
        klient.usunNal(n);
        fireTableDataChanged();
    }
    private List l;
    private Klient klient;
    private String columnNames[] = {
        "Kwota [z\u0142]", "Do zap\u0142aty [z\u0142]", "Rok"
    };
}
